package ro.dandanciu.webgallery.services.locator;

import org.apache.log4j.Logger;

import ro.dandanciu.webgallery.services.AdvertiseServices;
import ro.dandanciu.webgallery.services.GalleryServices;
import ro.dandanciu.webgallery.services.ImageServices;
import ro.dandanciu.webgallery.services.UserServices;

/**
 * Class for obtaining services.
 * It is a implementation of the singleton design pattern.
 * 
 * @author Dan
 *
 */
public class ServicesLocator {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(ServicesLocator.class);
	
	/*
	 * TODO make this more general 
	 * 	(for example using ids) 
	 *	with factory and spring initializaition
	 * example: http://www.javalobby.org/java/forums/t53127.html
	 */
	
	/** Holds the singleton instance */
	private static ServicesLocator instance;

	/**
	 * Private constructor, can be called only from within this class.
	 */
	private ServicesLocator() {
		if (logger.isDebugEnabled()) {
			logger.debug("Creating instance of ServicesLocator.");
		}
	}
	
	/**
	 * The method which is the only way for the outside world for obtaining
	 * a valid reference to this object.
	 * @return
	 */
	public static ServicesLocator getInstance() {
		if (instance == null) {
			instance = new ServicesLocator();
		}
		
		return instance;		
	}
	
	/** References to services. */
	private GalleryServices galleryServices;
	private ImageServices imageServices;
	private UserServices userServices;
	private AdvertiseServices advertiseServices;
	
	/** Getters and setters to services references. */
	public GalleryServices getGalleryServices() {
		return galleryServices;
	}
	public void setGalleryServices(GalleryServices galleryServices) {
		this.galleryServices = galleryServices;
	}
	public ImageServices getImageServices() {
		return imageServices;
	}
	public void setImageServices(ImageServices imageServices) {
		this.imageServices = imageServices;
	}
	public UserServices getUserServices() {
		return userServices;
	}
	public void setUserServices(UserServices userServices) {
		this.userServices = userServices;
	}

	public AdvertiseServices getAdvertiseServices() {
		return advertiseServices;
	}

	public void setAdvertiseServices(AdvertiseServices advertiseServices) {
		this.advertiseServices = advertiseServices;
	}
}
